#include "stdafx.h"
#include "globalmap.hpp"

namespace Data {

GlobalMap::GlobalMap()
{
}

GlobalMap::~GlobalMap()
{
}

uint GlobalMap::width() const
{
    return _width;
}

uint GlobalMap::height() const
{
    return _height;
}

const ICell &GlobalMap::cell(uint x, uint y) const
{
    return _cells[cind(x, y)];
}

void GlobalMap::create(uint width, uint height)
{
    std::vector<Cell> cells(width * height);
    _cells.swap(cells);
    _width = width;
    _height = height;
}

IEditableCell &GlobalMap::editableCell(uint x, uint y)
{
    return _cells[cind(x, y)];
}

//! returns cell index by it's 2d coordinates
uint GlobalMap::cind(uint x, uint y) const
{
#ifdef _DEBUG
    assert(x < _width);
    assert(y < _height);
#endif
    return (x + _width * y);
}

} // namespace Data
